package com.walkline.weibo.dao;

import java.util.Date;

import net.rim.device.api.i18n.SimpleDateFormat;

import org.json.me.JSONObject;

import com.walkline.util.StringUtility;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.GroupList;
import com.walkline.weibo.inf.User;

public class WeiboGroupList extends WeiboObject implements GroupList
{
	private long _id = 0;
	private String _id_str = "";
	private String _name = "";
	private String _mode = "";
	private int _visible = 0;
	private int _like_count = 0;
	private int _member_count = 0;
	private String _description = "";
	private String _profile_image_url = "";
	private User _user = null;
	private Date _created_at = new Date();

	public WeiboGroupList(WeiboSDK weibo, JSONObject jsonObject) throws WeiboException
	{
		super(weibo, jsonObject);

		JSONObject groupList = jsonObject;
		if (groupList != null)
		{
			_id = groupList.optLong("id");
			_id_str = groupList.optString("idstr");
			_name = groupList.optString("name");
			_mode = groupList.optString("mode");
			_visible = groupList.optInt("visible");
			_like_count = groupList.optInt("like_count");
			_member_count = groupList.optInt("member_count");
			_description = groupList.optString("description");
			_profile_image_url = groupList.optString("profile_image_url");

			if (!groupList.isNull("user")) {_user = new WeiboUser(weibo, groupList.optJSONObject("user"));}

			_created_at = StringUtility.parseDate(groupList.optString("created_at"));
		}
	}

	public long getId() {return _id;}

	public String getIdStr() {return _id_str;}

	public String getName() {return _name;}

	public String getMode() {return _mode;}

	public int getVisible() {return _visible;}

	public int getLikeCount() {return _like_count;}

	public int getMemberCount() {return _member_count;}

	public String getDescription() {return _description;}

	public String getProfileImageUrl() {return _profile_image_url;}

	public User getUser() {return _user;}

	/**
	 * 用户创建（注册）时间 (长日期)
	 * @return 格式为: "yyyy-MM-dd HH:mm"
	 */
	public String getCreatedAtLong()
	{
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");

		return sdf.formatLocal(_created_at.getTime());
	}

	/**
	 * 用户创建（注册）时间 (短日期)
	 * @return 格式为: "M/d HH:mm"
	 */
	public String getCreatedAtShort()
	{
		SimpleDateFormat sdf=new SimpleDateFormat("M/d HH:mm");

		return sdf.formatLocal(_created_at.getTime());
	}
}